package com.usefullc.chatgpt.filter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: Sampson
 * @date: 2022-10-19 22:09
 */
@Configuration
public class FilterConfig {

    @Autowired
    private ChatgptResourceHttpRequestHandler resourceHttpRequestHandler;


    @Bean
    public FilterRegistrationBean requestFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new ChatgptFilter(resourceHttpRequestHandler));
        registration.setName("chatgptFilter");
        registration.setOrder(1);
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("testName", "/test");
        registration.setInitParameters(paramMap);
        List<String> urlPatterns = new ArrayList<>();
        urlPatterns.add("/*");
        registration.setUrlPatterns(urlPatterns);
        return registration;
    }
}
